from restful.model import db


def UpdateInstance(instance, data=None):
    if instance is None:
        return

    if data is not None:
        for key, value in data.items():
            if hasattr(instance, key) and value is not None:
                setattr(instance, key, value)

    db.session.add(instance)
    db.session.commit()

